<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/webpage/include/taglib.jsp"%>
<html>
<head>
	<title>付款单管理</title>
	<meta name="decorator" content="ani"/>
	<script type="text/javascript">

		$(document).ready(function() {
			$("#inputForm").validate({
				submitHandler: function(form){
					jp.loading();
					form.submit();
				},
				errorContainer: "#messageBox",
				errorPlacement: function(error, element) {
					$("#messageBox").text("输入有误，请先更正。");
					if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
						error.appendTo(element.parent().parent());
					} else {
						error.insertAfter(element);
					}
				}
			});
			
	        $('#paymentDate').datetimepicker({
				 format: "YYYY-MM-DD HH:mm:ss"
		    });
            //当结算日期为空时，赋值当前时间
            if($("#dd").val()==""){
                document.getElementById("dd").value = getNowFormatDate();
            }
            //初始状态默认为已输入
            if($("#status").val()==""){
                $("#status").val(0);
            }
            //获取发票主表的结算方赋值给付款单的结算方
            if ($("#invoiceObj").val()) {
                $("#payeeName").val($("#invoiceObj").val());
            }
            //获取结算单主表的结算方赋值给付款单的结算方
            if ($("#feePayableName").val()) {
                $("#payeeName").val($("#feePayableName").val());
            }
        });

        <%--给日期赋初始值--%>
        function getNowFormatDate() {
            var date = new Date();
            var seperator1 = "-";
            var seperator2 = ":";
            var month = date.getMonth() + 1;
            var strDate = date.getDate();
            if (month >= 1 && month <= 9) {
                month = "0" + month;
            }
            if (strDate >= 0 && strDate <= 9) {
                strDate = "0" + strDate;
            }
            var minute = date.getMinutes();
            if (minute >= 0 && minute <= 9) {
                minute = "0" + minute;
            }
            var seconds = date.getSeconds();
            if (seconds >= 0 && seconds <= 9) {
                seconds = "0" + seconds;
            }
            var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate
                + " " + date.getHours() + seperator2 + minute + seperator2 + seconds;
            return currentdate;
        }
        function model(){
            all_ajax();
        }
        //弹出框提取数据ajax
        function all_ajax() {
            var tempPayables = searchPaymentId();
            var balance = $("#balance").val().trim();
            $.ajax({
                url: "${ctx}/fee/payment/findPayInvoiceList",
                data: {"status": 3, "clearUnit": balance, "tempPayables":tempPayables},
                success: function (data) {
                    console.log(data);
                    $("#payInvoiceDetailLists").empty();
                    $.each(data,function(index,item) {
                        var addTr = $("<tr id='"+item.id+"'></tr>");
                        addTr.appendTo("#payInvoiceDetailLists");
                        var td = ("<td>"+"<input id='"+item.id+"' value='"+item.id+"' type='checkbox' class='i-checks'>"+"</td>");
                        addTr.append(td);
                        if(item.status==1){
                            addTr.append($("<td id='status_"+item.id+"'>"+"</td>").text("已确认"));
                        }else{
                            addTr.append($("<td id='status_"+item.id+"'>"+"</td>").text("部分核销"));
						}
                        addTr.append($('<td></td>').text(item.invoiceNo));
                        addTr.append($('<td></td>').text(item.invoiceDate));
                        addTr.append($("<td id='payer_"+item.id+"'>"+"</td>").text(item.invoiceObj));
                        addTr.append($('<td></td>').text(item.invoiceMoney));
                        addTr.append($('<td></td>').text(item.remarks));
                    })
                },
                error: function (data) {
                    alert("操作失败!");
                }
            });
        }
        //获得所有选中的复选框的id
        function getCheckBox() {
            var boxs = "";		//设置变量，用于接收选中的复选框
            $("input:checkbox").each(function () {
                //判断复选框是否被选中
                if ($(this).is(':checked') && $(this).attr("id") != "allCheckBox") {
                    boxs += $(this).val();
                    boxs += ",";	//复选框的val()id集合以逗号分割
                }
            });
            return boxs;
        }

        //获取本次开票金额和应付账款id
        function inputBlur() {
            var countMoney = 0 * 1;
            var tempId = "";
            var inputId="";
            $("#contentTable tr:gt(0)").each(function (i) {
                $(this).children("td").each(function (j) {
                    if ($(this).attr("class") == "coun") {
                        inputId = $(this).attr("name") + "_theVcaMoney";
                        var tempMoney = $("#" + inputId).val();
                        if (isNaN(tempMoney)) {
                            alert("请输入数字");
                            $("#" + inputId).val(null);
                            return;
                        }
                        if (tempMoney >= 0) {
                            //获得开票金额
                            var voiceObj = $(this).attr("name") + "_invoiceMoney";
                            var voiceMoney = $("#" + voiceObj).text() * 1;
                            //获取已核销金额
                            var vcaObj = $(this).attr("name") + "_vcaMoney";
                            var vcaMoney = $("#" + vcaObj).text() * 1;
                            //alert("开票金额"+voiceMoney+"，已核销金额"+vcaMoney+",本次核销金额"+tempMoney);
                            //比较    本次核销金额    是否大于  开票金额-本次核销金额【如果大于，返回；如果小于，继续执行】
                            if (tempMoney > (voiceMoney - vcaMoney)) {
                                alert("本次核销金额不得大于未核销金额!");
                                $("#" + inputId).val(null);
                                return;
                            }
                            countMoney += tempMoney * 1;
                            tempId += $(this).attr("name") + "_" + tempMoney;
                            tempId += ",";
                        } else {
                            alert("核销金额不能小于零");
                            $("#" + inputId).val(null);
                            return;
                        }
                    }
                });
            });
            //获取付款金额
            var money = $("#money").val();
            var way = $("#operateType").val();
           if (money) {
                if (way == 'noDetail') {
                    if (countMoney > money) {	//判断付款金额是否小于引入发票明细累加的本次核销金额
                        alert("本次核销金额不得大于付款金额");
                        $("#"+inputId).val(null);
                        return;
                    }else{
                        $("#money").val(money);
                    }
                } else {
                    $("#money").val(countMoney);
                }
            } else {
                $("#money").val(countMoney);
            }
            $("#money").val(countMoney);
            var values = $("#ids").val();
            values = tempId;
            $("#ids").val(values);
        }
        //点击确认按钮将已输入状态修改为已确认状态
        function verify(id) {
           /* $.ajax({
                url : "${ctx}/fee/payment/updateStatus",
                data : {		 //参数值
                    "ids" :id
                },
                type:"post",
                success : function(data) {
                    location.reload();
                },
                error : function(data){
                    alert("操作失败!");
                }
            });*/
            window.location.href="${ctx}/fee/payment/updateStatusTwo?id="+id;
        }
        //不走后台，删除已经引入的明细
        function deleteInPage(id, inputId) {
            if (confirm("确定要删除吗？")) {
                //获取原来的付款金额
                var payMoney = $("#money").val() * 1;
                //获取本次核销金额
                var theVcaMoney = $("#" + inputId + "_theVcaMoney").val() * 1;
                //给付款单主表的付款金额重新赋值
                $("#money").val(payMoney - theVcaMoney);
                //alert("付款金额:"+payMoney+",本次核销金额:"+theVcaMoney);
                $("#detailTbody tr").each(function () {	//循环获取tr
                    var trId = $(this).attr("id");
                    if (trId == id) {
                        //获得页面原来的ids
                        var str = $("#ids").val();
                        var _str = str.trim().split(",");
                        str = "";
                        for (var i = 0; i < _str.length; i++) {
                            if (!(_str[i].indexOf(id) < 0)) {
                                //ids删除id,ids中原来包含的id置为空字符串
                                _str[i] = "";
                            }
                            //重新追加ids的值
                            str += _str[i] + ",";
                        }
                        //ids重新赋值
                        $("#ids").val(str);
                        //tbody删除id= 传入id的一行数据
                        $(this).remove();
                    }
                })
            }
        }
        //已输入状态下删除一条明细记录【从付款单明细表中删除】
        function deletes(id) {
            if (confirm("确定要删除吗？")) {
                window.location.href = "${ctx}/fee/payment/removePaymentDetail?id=" + id;
            }
        }
        //获取弹出框上查询按钮
        function searchDetail() {
            //加载层-默认风格
            layer.load();
            //此处演示关闭
            setTimeout(function () {
                layer.closeAll('loading');
            }, 500);
            all_ajax();
            payable_ajax();
        }
        //获取弹出框上重置按钮
        function reset() {//重置，页码清零
            $("#pageNo").val(0);
            $(".searchForm div.form-group input").val("");
            $(".searchForm div.form-group select").val("");
            //加载层-默认风格
            layer.load();
            //此处演示关闭
            setTimeout(function () {
                layer.closeAll('loading');
            }, 500);
            all_ajax();
            payable_ajax();
            return false;

        }
        //获取付款单主表id
        function searchPaymentId(){
            var paymentId = $("#paymentId").val();
            var tempPayable="";
            <%--同步请求--%>
            $.ajax({
                url : "${ctx}/fee/payment/findPaymentPayableDetailByPaymentId",
                async: false,
                data : {		 //参数值
                    "id" :paymentId
                },
                type:"post",
                success : function(data) {
                    console.log(data);
                    $.each(data, function (index, term) {
                        tempPayable += term.feePayable+",";
                    })
                    return tempPayable;
                },
                error : function(data){
                    alert("操作失败!");
                }
            });
            return tempPayable;
        }
        function invoiceDetail(){
            var tempIds = getCheckBox();
            var tempStr = tempIds.split(",");
            var ids = "";	//获取选中复选框的id
            var sc = "";	//机构名称变量
            var textName = "";
            if (tempIds == null || tempIds == "") {
                alert("请至少选择一条数据");
                return;
            }
            for (var i = 0; i < tempStr.length; i++) {
                if (!tempStr[i]) continue;
                var tempSc = $("#payer_" + tempStr[i]).text().trim();
                if (!sc) {
                    sc = tempSc;	//第一个元素赋值到sc
                } else if (sc != tempSc) {//上一个元素sc与本次循环的值不相等，不是同一个机构
                    alert("请选择相同结算方!");
                    return;
                }
                if ($("#status_" + tempStr[i]).text()) {
                    var text = $("#status_" + tempStr[i]).text().trim();
                    if (text == "已确认" || text == "部分核销") {
                        //状态为已确认和部分开票才能进行开票操作
                        textName = !textName ? text : textName;
                        if (text == textName) {
                            ids += tempStr[i] + ",";
                        } else {
                            alert("请选择相同状态的发票!");
                            return;
                        }
                    }
                } else return;
            }
            $('#myModal').modal('hide');
            $(".modal-backdrop").removeClass('in');
            layer.load();
            var target = "${target}";
            $.ajax({
                url: "${ctx}/fee/payment/addPayment",
                data: {		 //参数值
                    "ids": ids,
                    "type": 0,
                    "target": target
                },
                type: "post",
                success: function (data) {
                    //获取付款单主表应经存在的结算方
                    var payee = $("#payeeName").val();
                    if (data) {
                        var invoiceObj = "";
                        var list = eval(data);
                        var ids = $("#ids");
                        $.each(list, function (index, term) {
                            //获取引入发票明细的结算方
                            invoiceObj = term.feePayInvoice.invoiceObj;
                            //判断付款单主表的结算方不为空并和引入明细时的结算方比较是否相等
                            if (payee && payee != invoiceObj) {
                                alert("引入的结算方与付款单的结算方不一致！");
                                return;
                            } else {
                                var addTr = $("<tr id='" + term.feePayInvoice.id + "'></tr>");
                                addTr.appendTo("#detailTbody");
                                var td = ("<td>" + "<input id='" + term.id + "'  type='checkbox' class='i-checks'>" + "</td>");
                                addTr.append(td);
                                addTr.append($('<td></td>').text(term.feePayInvoice.entityNo));
                                addTr.append($("<td id='" + term.feePayInvoice.id + "_" + term.id + "_invoiceMoney'>" + "</td>").text(term.invMoney));
                                addTr.append($("<td id='" + term.feePayInvoice.id + "_" + term.id + "_vcaMoney'>" + "</td>").text(term.vcaMoney));
                                addTr.append("<td  class='coun' name='" + term.feePayInvoice.id + "_" + term.id + "'>" + "<input type='text' id='" + term.feePayInvoice.id + "_" + term.id + "_theVcaMoney' onchange=\"inputBlur()\"  class='form-control number required' value=''/>" + "</td>");
                                addTr.append($('<td></td>').text(term.remarks));
                                addTr.append("<td><a href='#' onclick=\"jp.openDialogView('查看应收发票明细', '${ctx}/fee/payInvoice/form?different=paymentPage&id=" + term.feePayInvoice.id + "','800px', '500px')\" class='btn btn-info btn-xs' ><i class='fa fa-search-plus'></i> 查看</a>"
                                    + "&nbsp;<input onclick=\"deleteInPage('" + term.feePayInvoice.id + "','" + term.feePayInvoice.id + "_" + term.id + "')\"  type='button' value='删除' class='btn btn-danger btn-xs'>" + "</td>");
                                var tempId = ids.val();
                                tempId += term.feePayInvoice.id;
                                tempId += ",";
                                ids.val(tempId);
                                //设置付款单主表的结算方
                                $("#payeeName").val(invoiceObj);
                            }
                        })
                        layer.closeAll('loading');
                    }
                },
                error: function (data) {
                    alert("操作失败!");
                    layer.closeAll('loading');
                }
            });
		}
		function btn_payable(){
            payable_ajax();
		}
        //结算单弹出框
        function payable_ajax(){
            var balance_payable = $("#balance_payable").val().trim();
            $.ajax({
                url : "${ctx}/fee/payment/findAllPayable",
                data:{"status":1 , "clearUnit": balance_payable},
                success: function(data) {
                    console.log(data);
                    $("#payableLists").empty();
                    var list = eval(data);
                    $.each(data,function(index,item) {
                        var addTr = $("<tr id='"+item.id+"'></tr>");
                        addTr.appendTo("#payableLists");
                        var td = ("<td>"+"<input id='"+item.id+"' value='"+item.id+"' type='checkbox' class='i-checks'>"+"</td>");
                        addTr.append(td);
                        if(item.status==1){
                            addTr.append($("<td id='status_"+item.id+"'>"+"</td>").text("已确认"));
                        }else{
                            addTr.append($("<td id='status_"+item.id+"'>"+"</td>").text("部分核销"));
						}
                        addTr.append($('<td></td>').text(item.clearingNo));
                        addTr.append($('<td></td>').text(item.busyDate));
                        addTr.append($("<td id='payer_"+item.id+"'>"+"</td>").text(item.payee.name));
                        addTr.append($('<td></td>').text(item.clearingMoney));
                        addTr.append($('<td></td>').text(item.remarks));
                    })
                },
                error : function(data){
                    alert("操作失败!");
                }
            });
        }

        //获得所有选中结算单的复选框的id
        function getPayableCheckBox(){
            var boxs = "";		//设置变量，用于接收选中的复选框
            $("input:checkbox").each(function() {
                //判断复选框是否被选中
                if ($(this).is(':checked') && $(this).attr("id") != "all_payable") {
                    boxs += $(this).val();
                    boxs += ",";	//复选框的val()id集合以逗号分割
                }
            });
            return boxs;
        }
        //点击结算单的提交后进行判断获取id
		function sure_payable(){
            var tempIds = getPayableCheckBox();
            var tempStr = tempIds.split(",");
            var ids = "";	//获取选中复选框的id
            var sc = "1";	//机构名称变量
            var textName = "";
            if (tempIds == null || tempIds == "") {
                alert("请至少选择一条数据");
                return;
            }
            for (var i = 0; i < tempStr.length-1; i++) {
                if (!tempStr[i]) continue;
                var tempSc = $("#payer_" + tempStr[i]).text().trim();
                if (sc=="1") {
                    sc = tempSc;	//第一个元素赋值到sc
                } else if (sc != tempSc) {//上一个元素sc与本次循环的值不相等，不是同一个机构
                    layer.alert("请选择相同的结算方!");
                    return;
                }
                if ($("#status_" + tempStr[i]).text()) {
                    var text = $("#status_" + tempStr[i]).text().trim();
                    if (text == "已确认"||text == "部分核销") {
                        //状态为已确认
                        textName = !textName ? text : textName;
                        if (text == textName) {
                            ids += tempStr[i] + ",";
                        }else {
                            alert("请选择相同状态的发票!");
                            return;
                        }
                    } else return;
                }
            }
            $('#modal_payable').modal('hide');
            $(".modal-backdrop").removeClass('in');
            $(".payable").addClass("active");
            $(".payInvoice").removeClass("active");
            $("#tab-2").addClass("active");
            $("#tab-1").removeClass("active");
            layer.load();
            //拼接表格数据
            $.ajax({
                url: "${ctx}/fee/payment/addPayableDetails",
                data: {		 //参数值
                    "ids": ids,
                },
                type: "post",
                success: function (data) {
                    //获取付款单主表应经存在的结算方
                    var payee = $("#payeeName").val();
                    if (data) {
                        var feePayableName = "";
                        var ids = $("#ids_payable");
                        var list = eval(data);
                        $.each(list, function (index, term) {
                            //获取引入发票明细的结算方
                            feePayableName = term.payee.name;
                            //判断付款单主表的结算方不为空并和引入明细时的结算方比较是否相等
                            if (payee && payee != feePayableName) {
                                alert("引入的结算方与付款单的结算方不一致！");
                                return;
                            }else{
                                var addTr = $("<tr id='" + term.id + "'></tr>");
                                addTr.appendTo("#payableDetailTbody");
                                var td = ("<td>" + "<input id='" + term.id + "'  type='checkbox' class='i-checks'>" + "</td>");
                                addTr.append(td);
                                addTr.append($('<td></td>').text(term.clearingNo));
                                addTr.append($("<td></td>").text(term.busyDate));
                                addTr.append($("<td  class='feeConsignorName'></td>").text(term.payee.name));
                                addTr.append($("<td id='" +term.id+ "_invoiceMoney'>"+"</td>").text(term.clearingMoney));
                                addTr.append($("<td id='"+term.id+"_vcaMoney'>"+"</td>").text(term.vcaMoney));
                                addTr.append("<td  class='coun' name='"+term.id+"'>"+"<input type='text' id='"+term.id+"_theVcaMoney' onchange=\"inputBlurPayable()\"  class='form-control required' value=''/>"+"</td>");
                                addTr.append($('<td></td>').text(term.remarks));
                                addTr.append("<td><a href='#' onclick=\"jp.openDialogView('查看结算单明细', '${ctx}/fee/payable/form?different=1&id=" + term.id + "','800px', '500px')\" class='btn btn-info btn-xs' ><i class='fa fa-search-plus'></i> 查看</a>"
                                    + "&nbsp;<input onclick=\"deleteInPagePayable('" + term.id + "','" + term.id + "')\"  type='button' value='删除' class='btn btn-danger btn-xs'>" + "</td>");
                                var tempId = ids.val();
                                tempId += term.id;
                                tempId += ",";
                                ids.val(tempId);
                                //设置付款单主表的结算方
                                $("#payeeName").val(feePayableName);
                            }
                        })
                        layer.closeAll('loading');
                    }
                },
                error: function (data) {
                    alert("操作失败!");
                    layer.closeAll('loading');
                }
            });
		}

        <%--不走后台，删除已经引入结算单的明细--%>
        function deleteInPagePayable(id, inputId) {
            if (confirm("确定要删除吗？")) {
                //获取原来的付款金额
                var payMoney = $("#money").val() * 1;
                //获取本次核销金额
                var theVcaMoney = $("#" + inputId + "_theVcaMoney").val() * 1;
                //给付款单主表的付款金额重新赋值
                $("#money").val(payMoney - theVcaMoney);
                //alert("付款金额:"+payMoney+",本次核销金额:"+theVcaMoney);
                $("#payableDetailTbody tr").each(function () {
                    var trId = $(this).attr("id");
                    if (trId == id) {
                        //获得页面原来的ids
                        var str = $("#ids_payable").val();
                        var _str = str.trim().split(",");
                        str = "";
                        for (var i = 0; i < _str.length; i++) {
                            if(!(_str[i].indexOf(id) < 0) ) {
                                //ids删除id,ids中原来包含的id置为空字符串
                                _str[i] = "";
                            }
                            //重新追加ids的值
                            str += _str[i] + ",";
                        }
                        //ids重新赋值
                        $("#ids_payable").val(str);
                        //tbody删除id= 传入id的一行数据
                        $(this).remove();
                    }
                })
            }
        }
        //删除资表记录【从付款单--结算单明细表中删除】
        function deletePaymentPayableDetail(id) {
            if (confirm("确定要删除吗？")) {
                window.location.href = "${ctx}/fee/payment/removePaymentPayableDetail?id=" + id;
            }
        }

        //获取本次核销金额和应付账款id
        function inputBlurPayable() {
            var countMoney = 0 * 1;
            var tempId = "";
            var inputId="";
            $("#contentTable_payable tr:gt(0)").each(function (i) {
                $(this).children("td").each(function (j) {
                    if ($(this).attr("class") == "coun") {
                        inputId = $(this).attr("name") + "_theVcaMoney";
                        var tempMoney = $("#" + inputId).val();
                        if (isNaN(tempMoney)) {
                            alert("请输入数字");
                            $("#" + inputId).val(null);
                            return;
                        }
                        if (tempMoney >= 0) {
                            //获得开票金额
                            var voiceObj = $(this).attr("name") + "_invoiceMoney";
                            var voiceMoney = $("#" + voiceObj).text() * 1;
                            //获取已核销金额
                            var vcaObj = $(this).attr("name") + "_vcaMoney";
                            var vcaMoney = $("#" + vcaObj).text() * 1;
                            //alert("开票金额"+voiceMoney+"，已核销金额"+vcaMoney+",本次核销金额"+tempMoney);
                            //比较    本次核销金额    是否大于  开票金额-本次核销金额【如果大于，返回；如果小于，继续执行】
                            if (tempMoney > (voiceMoney - vcaMoney)) {
                                alert("本次核销金额不得大于未核销金额!");
                                $("#" + inputId).val(null);
                                return;
                            }
                            countMoney += tempMoney * 1;
                            tempId += $(this).attr("name") + "_" + tempMoney;
                            tempId += ",";
                        } else {
                            alert("核销金额不能小于零");
                            $("#" + inputId).val(null);
                            return;
                        }
                    }
                });
            });
            //获取付款金额
            var money = $("#money").val();
            var way = $("#operateType").val();
            if (money) {
                if (way == 'noDetail') {
                    if (countMoney > money) {	//判断付款金额是否小于引入发票明细累加的本次核销金额
                        alert("本次核销金额不得大于付款金额");
                        $("#"+inputId).val(null);
                        return;
                    }else{
                        $("#money").val(money);
                    }
                } else {
                    $("#money").val(countMoney);
                }
            } else {
                $("#money").val(countMoney);
            }
            var values = $("#ids_payable").val();
            values = tempId;
            $("#ids_payable").val(values);
        }
	</script>
</head>
<body>
<div class="wrapper wrapper-content">				
<div class="row">
	<div class="col-md-12">
	<div class="panel panel-primary">
	<c:if test="${target eq 'invoice'}">
		<div class="panel-heading">
			<h3 class="panel-title">
				<a class="panelButton" href="${ctx}/fee/payInvoice"><i class="ti-angle-left"></i> 返回</a>
			</h3>
		</div>
	</c:if>
	<c:if test="${type ne 1}">
		<div class="panel-heading">
			<h3 class="panel-title">
				<a class="panelButton" href="${ctx}/fee/payment"><i class="ti-angle-left"></i> 返回</a>
			</h3>
		</div>
		<c:if test="${payment.status eq 0 or payment.id eq null}">
			<br>
		</c:if>
		<c:if test="${payment.id eq null or payment.status eq 0 or payment.status eq 2}">
			<button class="btn btn-primary btn-sm fl" data-toggle="modal" data-target="#myModal" onclick="model()">引入发票
			</button>
		</c:if>
		<%--添加引入结算单按钮--%>
		<c:if test="${payment.id eq null or payment.status eq 0 or payment.status eq 2}">
			<button class="btn btn-primary btn-sm fl" data-toggle="modal" data-target="#modal_payable" onclick="btn_payable()">引入结算单
			</button>
		</c:if>
		<c:if test="${payment.id ne null and payment.status eq 0}">
			<a href="#" onclick="verify('${payment.id}')" class="btn btn-success btn-sm"> 确认</a>
		</c:if>
	</c:if>
		<input type="hidden" value="${feePayment.operateType}" id="operateType">
		<div class="panel-body">
		<form:form id="inputForm" modelAttribute="payment" action="${ctx}/fee/payment/save" method="post" class="form-horizontal">
		<form:hidden path="id" id="paymentId"/>
		<sys:message content="${message}"/>
			<table class="table table-bordered  table-condensed dataTables-example dataTable no-footer">
				<tbody>
				<tr>
					<c:if test="${payInvoice.id ne null}">
						<td class="width-12 active"><label class="pull-right"><font color="red">*</font>付款单号：</label></td>
						<td class="width-21" >
							<form:input path="paymentNo" htmlEscape="false"    class="form-control required"/>
						</td>
					</c:if>
					<td class="width-12 active"><label class="pull-right"><font color="red">*</font>付款日期：</label></td>
					<td class="width-21" >
						<div class='input-group form_datetime' id='paymentDate'>
							<input type='text'  name="paymentDate" id="dd" class="form-control"  value="<fmt:formatDate value="${payment.paymentDate}" pattern="yyyy-MM-dd HH:mm:ss"/>"/>
							<span class="input-group-addon">
			                        <span class="glyphicon glyphicon-calendar"></span>
			                    </span>
						</div>
					</td>
					<td class="width-12 active"><label class="pull-right"><font color="red">*</font>状态：</label></td>
					<td class="width-21" >
						<select name="status" class="form-control required" id="status">
							<option value="">--请选择--</option>
							<option value="0" <c:if test="${payment.status eq 0}">selected</c:if>>已输入</option>
							<option value="1" <c:if test="${payment.status eq 1}">selected</c:if>>已确认</option>
							<option value="2" <c:if test="${payment.status eq 2}">selected</c:if>>部分核销</option>
							<option value="3" <c:if test="${payment.status eq 3}">selected</c:if>>全部核销</option>
						</select>
						<%--<form:input path="status" htmlEscape="false"    class="form-control required"/>--%>
					</td>
				</tr>
				<tr>
					<td class="width-12 active"><label class="pull-right"><font color="red">*</font>收款人：</label></td>
					<td class="width-21" >
							<sys:gridselect url="${ctx}/fee/consignor/data" id="payee" name="payee.id" value="${payment.payee.id}" labelName="payee.name" labelValue="${payment.payee.name}"
											title="选择收款人" cssClass="form-control required" fieldLabels="收款人" fieldKeys="name" searchLabels="收款人" searchKeys="name" ></sys:gridselect>
					</td>
					<td class="width-12 active"><label class="pull-right">付款金额：</label></td>
					<td class="width-21" >
						<form:input path="payMoney" htmlEscape="false"  id="money"  class="form-control  isFloatGteZero"/>
					</td>
					<td class="width-12 active"><label class="pull-right"><font color="red">*</font>支付方式：</label></td>
					<td class="width-21" >
						<form:select path="payMethod" class="form-control required">
							<form:option value="" label=""/>
							<form:options items="${fns:getDictList('pay_method_type')}" itemLabel="label" itemValue="value" htmlEscape="false"/>
						</form:select>
					</td>
				</tr>
				<tr>
					<td class="width-12 active"><label class="pull-right">备注信息：</label></td>
					<td class="width-21">
							<%--<form:textarea path="remarks" htmlEscape="false" rows="4"    class="form-control "/>--%>
						<form:input path="remarks" htmlEscape="false"    class="form-control "/>
					</td>
				</tr>
				</tbody>
			</table>
			<input type="hidden" id="ids" name="ids" value="${ids}"/>
			<input type="hidden" name="typeTarget" value="${target}"/>
			<input type="hidden" id="ids_payable" name="ids_payable" value=""/>
			<!-- 付款单明细表 -->
			<div class="tabs-container tab-container">
				<ul class="nav nav-tabs nav-style">
					<li class="active payInvoice"><a data-toggle="tab" href="#tab-1" aria-expanded="true">引入应收发票明细</a>
					</li>
					<li class="payable"><a data-toggle="tab" href="#tab-2" aria-expanded="false">引入结算单明细</a>
					</li>
				</ul>
				<div class="tab-content">
					<div  id="tab-1" class="tab-pane active tableBox">
						<table id="contentTable"
							   class="table table-striped table-bordered table-hover table-condensed dataTables-example dataTable contentTable">
							<thead>
							<tr>
								<th><input type="checkbox" class="i-checks" ></th>
								<th class="sort-column invoiceNo">发票号</th>
								<th class="sort-column invoiceMoney">开票金额</th>
								<th class="sort-column vcaMoney">已核销金额</th>
								<th class="sort-column theVcaMoney">本次付款金额</th>
								<th class="sort-column remarks">备注信息</th>
								<th>操作</th>
							</tr>
							</thead>
							<tbody id="detailTbody">
							<c:forEach items="${list}" var="feePaymentDetail">
								<%--结算方--%>
								<input type="hidden" name="invoiceObj" id="invoiceObj"
									   value="${feePaymentDetail.feePayInvoice.invoiceObj}"/>
								<tr id="${feePaymentDetail.feePayInvoice.id}">
									<td><input type="checkbox" id="${feePaymentDetail.feePayInvoice.id}" class="i-checks"></td>
									<td><%--发票号(实体票号)--%>
										<c:if test="${sign eq 'invoice'}">
											<a href="#"
											   onclick="jp.openDialogView('查看应收发票明细', '${ctx}/fee/payInvoice/form?different=paymentPage&id=${feePaymentDetail.feePayInvoice.id}','800px', '500px')">
													${feePaymentDetail.feePayInvoice.entityNo}
											</a>
										</c:if>
										<c:if test="${flag eq 'payment'}"><!--different标记用在发票form页面判断显示还是隐藏信息-->
										<a href="#"
										   onclick="jp.openDialogView('查看应收发票明细', '${ctx}/fee/payInvoice/form?different=paymentPage&id=${feePaymentDetail.feePayInvoice.id}','950px', '500px')">
												${feePaymentDetail.invoiceNo}
										</a>
										</c:if>
									</td>
									<td id="${feePaymentDetail.feePayInvoice.id}_${feePaymentDetail.id}_invoiceMoney">
											<%--开票金额--%>
												<c:if test="${sign eq 'invoice'}">
													<fmt:formatNumber value=" ${feePaymentDetail.invMoney}" pattern="#.00"/>
												</c:if>
												<c:if test="${flag eq 'payment'}">
													<fmt:formatNumber value="${feePaymentDetail.invoiceMoney}" pattern="#.00"/>
												</c:if>
									</td>
									<td id="${feePaymentDetail.feePayInvoice.id}_${feePaymentDetail.id}_vcaMoney">
											<%--已核销金额--%>
										<c:if test="${feePaymentDetail.vcaMoney ne null and feePaymentDetail.vcaMoney > 0}">
											<fmt:formatNumber value=" ${feePaymentDetail.vcaMoney}" pattern="#.00"/>
										</c:if>
									</td>
									<td class="coun"
										name="${feePaymentDetail.feePayInvoice.id}_${feePaymentDetail.id}">    <%--发票id，发票子表id --%>
											<%--本次核销金额--%>
										<c:if test="${flag eq 'payment'}">
											<input type="text"
												   id="${feePaymentDetail.feePayInvoice.id}_${feePaymentDetail.id}_theVcaMoney"
												   disabled="disabled"
												   value="${feePaymentDetail.theVcaMoney}" style="border:none;background:#FFFFFF"/>
										</c:if>
										<c:if test="${sign eq 'invoice'}">    <%--发票id，发票子表id 本次核销金额--%>
											<input type="text"
												   id="${feePaymentDetail.feePayInvoice.id}_${feePaymentDetail.id}_theVcaMoney"
												   style="border:none;background:#FFFFFF" class="form-control number required"
												   onchange="inputBlur()"/>
										</c:if>

									</td>
									<td>
											<%--备注--%>
												<c:if test="${sign eq 'invoice'}">
													${feePaymentDetail.feePayInvoice.remarks}
													<input type="hidden" name="type" value="typeInvoice"/>
												</c:if>
												<c:if test="${flag eq 'payment'}">
													${feePaymentDetail.remarks}
												</c:if>
									</td>
									<td>
										<c:if test="${sign eq 'invoice'}">
											<a href="#"
											   onclick="jp.openDialogView('查看应收发票明细', '${ctx}/fee/payInvoice/form?different=paymentPage&id=${feePaymentDetail.feePayInvoice.id}','800px', '500px')"
											   class="btn btn-info btn-xs"><i class="fa fa-search-plus"></i> 查看</a>
										</c:if>
										<c:if test="${flag eq 'payment'}">
											<a href="#"
											   onclick="jp.openDialogView('查看应收发票明细', '${ctx}/fee/payInvoice/form?different=paymentPage&id=${feePaymentDetail.feePayInvoice.id}','950px', '500px')"
											   class="btn btn-info btn-xs"><i class="fa fa-search-plus"></i> 查看</a>
										</c:if>
										<c:if test="${payment.id ne null and payment.status eq 0}">
											<input type="button" onclick="deletes('${feePaymentDetail.id}')" value="删除"
												   class="btn btn-danger btn-xs">
										</c:if>
										<c:if test="${payment.id eq null}">
											<input type="button" onclick="deleteInPage('${feePaymentDetail.feePayInvoice.id}','${feePaymentDetail.feePayInvoice.id}_${feePaymentDetail.id}')" value="删除"  class="btn btn-danger btn-xs">
										</c:if>
									</td>
								</tr>
							</c:forEach>
							</tbody>
						</table>
					</div>

					<!-- 结算单明细表 -->

					<!-- 表格 -->
					<div id="tab-2" class="tab-pane tableBox">
						<table id="contentTable_payable" class="table table-striped table-bordered table-hover table-condensed dataTables-example dataTable contentTable">
							<thead>
							<tr>
								<th> <input type="checkbox" class="i-checks"></th>
								<th>结算单号</th>
								<th>结算日期</th>
								<th>结算方</th>
								<th>结算金额</th>
								<th>已核销金额</th>
								<th>本次付款金额</th>
								<th>备注信息</th>
								<th>操作</th>
							</tr>
							</thead>
							<tbody id="payableDetailTbody">
							<c:forEach items="${PaymentPayableDetails}" var="details" >

								<tr id="${details.id}">
									<td> <input type="checkbox" id="${details.id}" value="${details.id}" class="i-checks"></td>
									<td>
											${details.clearingNo}
									</td>
									<td>

											<fmt:formatDate value="${details.busyDate}" pattern="yyyy-MM-dd HH:mm:ss"/>
									</td>
									<td>
											${details.feeConsignor.name}
									</td>
									<td id="${details.id}_invoiceMoney">
										<fmt:formatNumber value="${details.clearingMoney}" pattern="#.00"/>
									</td>
									<td id="${details.id}_vcaMoney">
										<c:if test="${details.vcaMoney ne null and details.vcaMoney > 0}">
											<fmt:formatNumber value="${details.vcaMoney}" pattern="#.00"/>
										</c:if>
									</td>
									<td class="coun" name="${details.id}">
										<c:if test="${sign eq 'sign'}">
											<input type="text" id="${details.id}_theVcaMoney" disabled="disabled"
												   value="${details.theVcaMoney}" class="form-control required" style="width:200px;"/>
										</c:if>
										<c:if test="${flag eq 'payable'}">
											<input type="text" id="${details.id}_theVcaMoney"
												   onchange="inputBlurPayable()" value="" class="form-control required" style="width:200px;"/>
										</c:if>
									</td>
									<td>
											${details.remarks}
									</td>
									<td>
										<a href="#" onclick="jp.openDialogView('查看应付结算单明细', '${ctx}/fee/payable/form?different=1&id=${details.feePayable.id}','800px', '500px')" class="btn btn-info btn-xs" ><i class="fa fa-search-plus"></i> 查看</a>
										<c:if test="${payment.id ne null and payment.status eq 0}">
											<input type="button" onclick="deletePaymentPayableDetail('${details.id}')" value="删除"
												   class="btn btn-danger btn-xs">
										</c:if>
									</td>
								</tr>
							</c:forEach>
							</tbody>
						</table>
					</div>
				</div>
			</div>
		<c:if test="${fns:hasPermission('fee:payment:edit') || isAdd}">
				<div class="col-lg-3"></div>
		        <div class="col-lg-6">
		             <div class="form-group text-center">
		                 <div>
		                     <button class="btn btn-primary btn-block btn-lg btn-parsley" data-loading-text="正在提交...">提 交</button>
		                 </div>
		             </div>
		        </div>
		</c:if>
		</form:form>
		</div>				
	</div>
	</div>
</div>
</div>
<!-- 模态框（Modal） -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
	<div class="modal-dialog" style="width: 750px">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
				<h4 class="modal-title" id="myModalLabel">应收发票列表</h4>
			</div>
			<div class="modal-body">
				<!-- 查询条件 -->
				<div class="row">
					<div class="col-sm-12">
						<form action="" method="post" class="form-inline searchForm" id="searchForm">
							<div class="form-group pull-left">
								<span>结算方：</span>
								<input value="" type="text" name="balance" id="balance" title=""
									   class="form-control input-sm"/>
							</div>
						</form>
						<div class="pull-right">
							<button class="btn btn-primary btn-rounded btn-outline btn-sm " onclick="searchDetail()"><i
									class="fa fa-search"></i> 查询
							</button>
							<button class="btn btn-primary btn-rounded btn-outline btn-sm " onclick="reset()"><i
									class="fa fa-refresh"></i> 重置
							</button>
						</div>
					</div>
				</div>
				<!-- 表格 -->
				<div class="table-box1">
					<table id="content"
						   class="table table-striped table-bordered table-hover table-condensed dataTables-example dataTable tableAjax">
						<thead>
						<tr>
							<th><input type="checkbox" class="checkbox_css" id="allCheckBox" name="all"></th>
							<th class="sort-column status">状态</th>
							<th class="sort-column invoiceNo">发票单号</th>
							<th class="sort-column invoiceDate">开票日期</th>
							<th class="sort-column invoiceObj">结算方</th>
							<th class="sort-column invoiceMoney">开票金额</th>
							<th class="sort-column remarks">备注信息</th>
						</tr>
						</thead>
						<tbody id="payInvoiceDetailLists">
						</tbody>
					</table>
				</div>
			</div>
			<div class="modal-footer">
				<button type="button" class="btn btn-primary" onclick="invoiceDetail()">确定</button>
				<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
			</div>
		</div><!-- /.modal-content -->
	</div><!-- /.modal -->
</div>
<!-- 引入结算单模态框（Modal） -->
<div class="modal fade" id="modal_payable" tabindex="-1" role="dialog" aria-labelledby="title_payable" aria-hidden="true">
	<div class="modal-dialog" style="width: 750px">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
				<h4 class="modal-title" id="title_payable">应付结算单列表</h4>
			</div>
			<div class="modal-body">
				<!-- 查询条件 -->
				<div class="row">
					<div class="col-sm-12">
						<form action="" method="post" class="form-inline searchForm" id="">
							<div class="form-group pull-left">
								<span>结算方：</span>
								<input value="" type="text" name="balance_payable" id="balance_payable" title="" class="form-control input-sm"/>
							</div>
						</form>
						<div class="pull-right">
							<button  class="btn btn-primary btn-rounded btn-outline btn-sm " onclick="searchDetail()" ><i class="fa fa-search"></i> 查询</button>
							<button  class="btn btn-primary btn-rounded btn-outline btn-sm " onclick="reset()" ><i class="fa fa-refresh"></i> 重置</button>
						</div>
					</div>
				</div>
				<!-- 表格 -->
				<div  class="table-box1">
					<table id="content_payable" class="table table-striped table-bordered table-hover table-condensed dataTables-example dataTable tableAjax_payable">
						<thead>
						<tr>
							<th> <input type="checkbox" class="checkbox_css" id="all_payable" name="all"></th>
							<th  class="sort-column status">状态</th>
							<th  class="sort-column clearingNo">结算单号</th>
							<th  class="sort-column busyDate">结算日期</th>
							<th  class="sort-column payee">结算方</th>
							<th  class="sort-column clearingMoney">结算金额</th>
							<th  class="sort-column remarks">备注信息</th>
						</tr>
						</thead>
						<tbody id="payableLists">
						</tbody>
					</table>
				</div>
			</div>
			<div class="modal-footer">
				<button type="button" class="btn btn-primary" onclick="sure_payable()" >确定</button>
				<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>

			</div>
		</div><!-- /.modal-content -->
	</div><!-- /.modal -->
</div>
</body>
</html>